package com.hzdl.cinema.service.impl;

import com.hzdl.cinema.dao.RepertoireDao;
import com.hzdl.cinema.dao.impl.RepertoireDaoImpl;
import com.hzdl.cinema.domain.PageBean;
import com.hzdl.cinema.domain.Play;
import com.hzdl.cinema.service.RepertoireService;

import java.util.List;

public class RepertoireServiceImpl implements RepertoireService {

        RepertoireDao repertoireDao=new RepertoireDaoImpl();
    @Override
    public PageBean<Play> playRepertoire(Integer rows, Integer currentPage,String select_button) {
        PageBean<Play> pageBean=new PageBean<>();

        //    totalCount;//总条数
     int   totalCount= repertoireDao.totalRepertoire(select_button);
     pageBean.setTotalCount(totalCount);
        //    totalPage;//总页数
        int totalPage = totalCount % rows == 0 ? totalCount / rows : (totalCount / rows) + 1;
        pageBean.setTotalPage(totalPage);
        //    currentPage;//当前页
        pageBean.setCurrentPage(currentPage);
        //    rows;//每页的条数
        pageBean.setRows(rows);
        //list
        int index = (currentPage - 1) * rows;
         List<Play> list= repertoireDao.fiedRepertoire(index,rows,select_button);
        pageBean.setList(list);


        return pageBean;
    }

    @Override
    public void addPlay(Play play) {

        repertoireDao.addPlay(play);


    }

    @Override
    public void deletePlay(String id) {
        repertoireDao.deletePlay(id);
    }

    @Override
    public Play playEcho(String id) {
       Play play =  repertoireDao.playEcho(id);
        return play;
    }

    @Override
    public void playUpdete(Play play) {

        repertoireDao.playUpdete(play);
    }


}
